* Empty quarterly dataset
* =============================
clear
gen date_quarterly = . 
format date_quarterly %tq 

* Merge
* =========
merge 1:1 date_quarterly using ${dirTemp}/fred_data_quarterly, nogen keepusing(FFR GS1 GS2 RGDP laborProd GDPDEF CPI RND)
merge 1:1 date_quarterly using ${dirTemp}/tfp, nogen
merge 1:1 date_quarterly using ${dirTemp}/tfpplus, nogen 
merge 1:1 date_quarterly using ${dirInput}/hfi_mpshocks_final_quarterly, nogen keepusing(ffr3shockTightWeighted policyShockTightWeighted ffr3shockTightAllWeighted ffr3shockTightSignWeighted ffr3shockTightNoQEWeighted ffr3shockTightGBWeightedUncorr)

* Transformations
* ===================
gen logRND = log(RND/GDPDEF)
drop RND
gen logLaborProd = log(laborProd)
drop laborProd
gen logGDP = log(RGDP)
drop RGDP

* Transform to index = 1 at 2005Q1
* ====================================
foreach x of varlist logTFP logTFPplusUtil logTFPplus logTFPUtil logLaborProd {
	gen aux1 = `x' if date_quarterly == yq(2005,1)
	egen aux2 = mean(aux1)
	replace `x' = `x' - aux2 + 1
	drop aux*
}

* Sign-specific shocks
* ==========================
rename ffr3shockTightGBWeightedUncorr ffr3shockTightGBWeiUncorr // abbreviate
foreach mpshock of varlist ffr3shockTightWeighted policyShockTightWeighted ffr3shockTightAllWeighted ffr3shockTightSignWeighted ffr3shockTightNoQEWeighted ffr3shockTightGBWeiUncorr {
	gen `mpshock'Exp = 0
	replace `mpshock'Exp = -`mpshock' if `mpshock' < 0 
	gen `mpshock'Cont = 0 
	replace `mpshock'Cont = `mpshock' if `mpshock' > 0
}

* Save
* ==========
tsset date_quarterly  
save ${dirTemp}/tsdata_macro, replace
